/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package createTable;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author tea milandi
 */
public class CreateTable {
    public static void main(String[] args) {
        String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
        String userid = "mhs115314008"; // gantikan dengan username anda
        String password = "mhs115314008"; // gantikan dengan password anda
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(password);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            statement.executeQuery("create table barang_asmart (idbarang varchar2(4) constraint barang_asmart_pk primary key,"
                    + " namabarang varchar2(20) not null unique,"
                    + " jumlahbarang number(6) not null,"
                    + " hargabarang number(6) not null)");
            statement.executeQuery("create table user_asmart (username varchar2(10) constraint user_asmart_pk primary key,"//1
                    + " namauser varchar2(25) not null,"
                    + " jenisuser varchar2(8) not null,"
                    + " password varchar2(10) not null)");
            statement.executeQuery("create table pemesanan_asmart (kodepemesanan varchar2(9) constraint pemesanan_asmart_pk primary key ,"//2
                    + " waktupemesanan varchar2(10) not null,"
                    + " jumlahbarang number(6) not null,"
                    + " idbarang varchar2(20) constraint pemesanan_asmart_fk1 references barang_asmart(idbarang),"
                    + " username varchar2(6) constraint pemesanan_asmart_fk2 references user_asmart(username),"
                    + " status_pengiriman varchar2(8) not null)");
            statement.executeQuery("create table penerimaan_asmart (kodepenerimaan varchar2(9) constraint penerimaan_asmart_pk primary key ,"//2
                    + " waktupenerimaan varchar2(10) not null,"
                    + " jumlahbarang number(6) not null,"
                    + " hargabarang number(6) not null,"
                    + " idbarang varchar2(4) constraint penerimaan_asmart_fk1 references barang_asmart(idbarang),"
                    + " username varchar2(10) constraint penerimaan_asmart_fk2 references user_asmart(username))");            
            statement.executeQuery("create table pengiriman_asmart (kodepengiriman varchar2(9) constraint pengiriman_asmart_pk primary key ,"//3
                    + " waktupengiriman varchar2(10) not null,"
                    + " kodepemesanan constraint pengiriman_asmart_fk1 references pemesanan_asmart(kodepemesanan),"
                    + " username constraint pengiriman_asmart_fk2 references user_asmart(username),"
                    + " jumlahbarang number(6) not null,"
                    + " idbarang varchar2(4) constraint pengiriman_asmart_fk3 references barang_asmart(idbarang),"
                    + " hargabarang number(6) not null)");
            
            System.out.println("semua table created");
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
